//封装自定义的hooks,用来发起请求,以及获取道请求得到的数据
import { rootState, rootThunkAction } from '@/types/store';
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
export const useInitialState = <T extends keyof rootState>(
  action: () => rootThunkAction,
  stateName: T
) => {
  const dispatch = useDispatch();
  const state = useSelector((state: rootState) => state[stateName]);
  useEffect(() => {
    dispatch(action());
    return () => {};
  }, [dispatch, action]);
  return state;
};
